import { Geometry } from "./Geometry";
import { any, all, has } from "../core/logic";
import { process } from "../process/worker/process";
/**
 * @class
 * @memberof w.geometry
 */
class CircleGeometry extends Geometry {
  /**
   * 圆平面构造方法
   * @param {*} opts
   * @param {Number} opts.radius 【可选值】圆半径，缺省值：1。
   * @param {Number} opts.section 【可选值】圆周的分段数，段数越大，圆越圆滑，同时也会消耗更多的内存，缺省值：12。
   * @param {Boolean} opts.back 【可选值】是否开启后台线程构造圆，缺省值：true，在后台进行解析。
   * @example
   * let c=new w.geometry.CircleGeometry({radius:2});
   */
  constructor(opts = {}) {
    super(opts);
    this.type = "CircleGeometry";
    this.position = null;
    this._radius = any(opts.radius, 1);
    this._section = any(opts.section, 12);
    this.back = any(opts.back, false);
    this.createCircle();
  }
  set back(v){
    this._back = v;
    return this;
  }
  get back(){
    return this._back;
  }
  set radius(v){
    this._radius = v;
    this.createCircle();
    return this;
  }
  get radius(){
    return this._radius;
  }
  set section(v){
    this._section = v;
    this.createCircle();
    return this;
  }
  get section(){
    return this._section;
  }
  createCircle() {
    if (all(has(this.section), has(this.radius))) {
      let info = { back: this.back, section: this.section, radius: this.radius, type: "createCircle" }
      process(info, (message) => {
        let { position, indices,texCood0,normal } = message.data;
        this.position = new Float32Array(position);
        this.normal = new Float32Array(normal);
        this.texCood0 = new Float32Array(texCood0);
        this.indices = new Uint32Array(indices);
      })
    }
  }
}

export { CircleGeometry }
